import request from '@/utils/request'
import { filtersRaw, pageRequsetBody } from '@/utils'
import Vue from 'vue'
/** 查询所有通话记录*/
export function getCallLog() {
  return request({
    method: 'GET',
    url: '/call-center/api/v1/calllog'
  })
}
/** 新增 呼叫类型 1:呼入，2：普通呼出，3：未接呼出，4：外呼任务呼出，5：呼入转接 0：全部
 * @params {object} data
 */
export function postCreate(data) {
  data.callPlatform = Vue.prototype.$cps?.callPlatform ?? ''
  return request({
    method: 'POST',
    url: '/call-center/api/v1/callLog/create',
    data
  })
}
/** 修改
 * @params {object} data
 */
export function putCreate(data) {
  return request({
    method: 'PUT',
    url: '/call-center/api/v1/callLog',
    data
  })
}
/** 今日呼入呼出量
 */
export function count() {
  return request({
    method: 'GET',
    url: '/call-center/api/v1/callLog/count',
    hiddenError: true
  })
}
/** 获取录音地址 */
export function putRename(filePath) {
  return request({
    method: 'PUT',
    url: '/call-center/api/v1/voiceFile/rename',
    headers: {
      'Content-Type': 'application/json'
    },
    data: filePath,
    transformRequest: [function(data, headers) {
      // 对 data 进行任意转换处理
      return data
    }]
  })
}

/** 根据callCode查询一条通话记录 */
export function getCallRecordByCallCode(callCode) {
  return request({
    method: 'POST',
    url: '/call-center/api/v1/callLog/page',
    data: pageRequsetBody({
      pageFlag: false,
      filtersRaw: [filtersRaw('callCode', callCode, '=')]
    })
  })
}

/**
 * 释放公司号码
 * @param {*} companyPhone
 * @returns
 */
export function releaseCompanyPhone(companyPhone) {
  return request({
    url: `/call-center/api/v1/callLog/release/${companyPhone}`,
    method: 'PUT'
  })
}
